package com.itcast.stargraph.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itcast.stargraph.mapper.SgUserResultMapper;
import com.itcast.stargraph.pojo.SgUserResult;
import com.itcast.stargraph.service.ISgUserResultService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 生产的结果信息表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-06-12
 */
@Service
public class SgUserResultServiceImpl extends ServiceImpl<SgUserResultMapper, SgUserResult> implements ISgUserResultService {
    
    
    @Override
    public void insertUserResult(Long userId, List<String> urls) {
        // 1.封装数据
        List<SgUserResult> list = urls.stream().map(url -> {
            SgUserResult userResult = new SgUserResult();
            userResult.setUrl(url);
            userResult.setCreatedTime(LocalDateTime.now());
            userResult.setUserId(userId);
            userResult.setCollect(0);
            return userResult;
        }).collect(Collectors.toList());
        //2.执行批量保存
        this.saveBatch(list);
    }
}
